{extend name="layout:base" /}
{block name="page_content"}
  <form class="form-horizontal adminform" id="model-form" method="post" action="">
    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right">
        登录名：<span class="red">*</span>
      </label>
      <div class="col-sm-10">
        <input type="text" name="name" placeholder="请输入用户的登录名" class="col-xs-10 col-sm-5" value="{$member.name|default=''}" required autocomplete="off" />
      </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right">
        真实姓名：
      </label>
      <div class="col-sm-10">
        <input type="text" name="nickname" placeholder="请输入用户真实姓名" class="col-xs-10 col-sm-5" value="{$member.nickname|default=''}" autocomplete="off" />
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        管理员组名：<span class="red">*</span>
      </label>
      <div class="col-sm-10">
        <select name="group_id">
          {volist name="groups" id="vo"}
            <?php if(isset($member['group_id']) && $member['group_id']==$vo['id']): ?>
              <option value="{$vo.id}" selected="selected">{$vo.title}</option>
            <?php else: ?>
              <option value="{$vo.id}">{$vo.title}</option>
            <?php endif; ?>
          {/volist}
        </select>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right">
        登录密码：<span class="red">*</span>
      </label>
      <div class="col-sm-10">
        <input type="password" name="password_hide"  style="display:none"/>
        <input type="password" id="password" name="password" placeholder="请输入用户的登录密码" class="col-xs-10 col-sm-5" value="" autocomplete="off" required/>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right">
        再次输入密码：<span class="red">*</span>
      </label>
      <div class="col-sm-10">
        <input type="password" id="confirm_password" name="confirm_password" placeholder="请再次输入用户的登录密码" class="col-xs-10 col-sm-5" value="" autocomplete="off" required/>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 显示状态：  </label>
      <div class="col-sm-10" style="padding-top:5px;">
        <input name="status" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" <?php if(isset($member["status"]) && intval($member["status"])){echo('checked="checked"');} ?> />
        <span class="lbl"></span>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="clearfix form-actions">
      <div class="col-md-offset-3 col-md-9">
        <button class="btn btn-info" type="submit">
          <i class="ace-icon fa fa-check bigger-110"></i>
          保存
        </button>

        &nbsp; &nbsp; &nbsp;
        <a class="btn" href="{:url('index')}">
          <i class="ace-icon fa fa-undo bigger-110"></i>
          返回
        </a>
      </div>
    </div>
  </form>
{/block}
{block name="page_js"}
  <script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      var $form = $("form#model-form");
      $form.validate({
        rules:{
          'name': {
            required: true,
            minlength: 2,
            maxlength: 30,
            remote: {
              url: "{:url('ajax_check_unique')}",
              type: "post",
              data: {
                field: "name",
                id: function(){
                  var id = 0;
                  if($form.find("input#id").length){
                    id = $form.find("input#id").val();
                  }
                  return id;
                }
              }
            }
          },"nickname":{
            minlength: 3,
            maxlength: 30
          }, 'mobile':{
            min: 13000000000,
            max: 19900000000
          },"password":{
            minlength: 6,
            maxlength: 20
          },"confirm_password":{
            equalTo: "#password"
          }
        },
        messages:{
          'name': {
            required: '用户登录名不能为空',
            minlength: '登录名长度必须在2-30个字符之间',
            maxlength: '登录名长度必须在2-30个字符之间',
            remote: '相同登录名已存在'
          },'nickname': {
            minlength: "用户昵称长度必须在2-30个字符之间",
            maxlength: "用户昵称长度必须在2-30个字符之间"
          },
          "mobile":{
            min: "用户手机号码正确",
            max: "用户手机号码正确"
          },"nickname":{
            required: "请输入用户昵称",
            minlength: "用户昵称长度必须在2-30个字符之间",
            maxlength: "用户昵称长度必须在3-30个字符之间"
          },"password":{
            minlength: "登录密码长度必须在6-20之间",
            maxlength: "登录密码长度必须在6-20之间"
          },"confirm_password":{
            equalTo: "两次输入的密码一致"
          }
        },
        errorClass: "help-inline input-error",
        errorElement: "span",
        highlight:function(element, errorClass, validClass) {
          $(element).parents('.form-group').addClass('has-error');
        },
        unhighlight: function(element, errorClass, validClass) {
          $(element).parents('.form-group').removeClass('has-error');
        },
        submitHandler: function(form){
          var $form = $(form);
          $.ajax({
            url: $form.attr("action"),
            type: $form.attr("method"),
            dataType: "JSON",
            data: $form.serialize(),
            success: function(res){
              if(res['code']){
                location.href = res['url'];
              }else{
                alert(res['msg']);
              }
            }, error: function () {
              alert("数据执行错误！");
            }
          });
        }
      });
    });
  </script>
{/block}